package com.tang.excel.oci.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.tang.excel.oci.domain.GullyWarmWater;
import com.tang.excel.oci.mapper.GullyWarmWaterMapper;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author Tang
 * @classname GullyWarmWaterListener
 * @description [  ]
 * @date 2021/6/3 15:15
 */
public class GullyWarmWaterListener extends AnalysisEventListener<GullyWarmWater> {

    GullyWarmWaterMapper gullyWarmWaterMapper;

    List<GullyWarmWater> gullyWarmWaters = new ArrayList<>();

    public GullyWarmWaterListener(GullyWarmWaterMapper gullyWarmWaterMapper) {
        this.gullyWarmWaterMapper = gullyWarmWaterMapper;
    }

    @Override
    public void invoke(GullyWarmWater gullyWarmWater, AnalysisContext analysisContext) {

        gullyWarmWater.setCodValue(Double.valueOf(gullyWarmWater.getCod().replace("(mg/L)", "")));

        gullyWarmWater.setWarmCodeValue(Double.valueOf(gullyWarmWater.getWarmCode().replace("(mg/L)", "")));
        gullyWarmWater.setEmissionsValue(Integer.valueOf(gullyWarmWater.getEmissions().replace("(吨)", "")));
        gullyWarmWater.setWastewaterFlowValue(Double.valueOf(gullyWarmWater.getWastewaterFlow().replace("(L/s)", "")));

        gullyWarmWater.setOperatorUser("admin");
        gullyWarmWater.setUpdateTime(new Date());
        gullyWarmWaters.add(gullyWarmWater);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        gullyWarmWaterMapper.batchInsert(gullyWarmWaters);
    }
}